package OptionsManager;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/**
 *
 * @author Martin Haulrich
 */
public class AbstractOptions extends Properties {

    public AbstractOptions() {
        super(new Properties());
    }

    public AbstractOptions(Properties defaults) {
        super(defaults);
    }


    public String getDefaults() {
        return this.defaults.toString();
    }

    public double getDoubleOption(String key) {
        return Double.parseDouble(getProperty(key));
    }

    public void setDoubleOption(String key, double value) {
        setProperty(key, value + "");
    }

    public int getIntOption(String key) {
        return Integer.parseInt(getProperty(key));
    }

    public void setIntOption(String key, int value) {
        setProperty(key, value + "");
    }

    public void store(String fn) throws IOException {
        OutputStream outStream = new FileOutputStream(fn);
        store(outStream, "");
        outStream.close();
    }

    public void storeToXML(String fn) throws IOException {
        OutputStream outStream = new FileOutputStream(fn);
        storeToXML(outStream, "");
        outStream.close();
    }

    public void load(String fn) throws IOException {
        InputStream inStream = new FileInputStream(fn);
        load(inStream);
        inStream.close();
    }

    public void loadFromXML(String fn) throws IOException {
        InputStream inStream = new FileInputStream(fn);
        loadFromXML(inStream);
        inStream.close();
    }
}
